package com.cjf.weather.weathercollection.job;

import com.cjf.weather.weathercollection.service.service.WeatherDataCollectionService;
import com.cjf.weather.weathercollection.vo.City;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.ArrayList;
import java.util.List;

/**
 * @author cjf
 * @description
 * @create 2019-03-27 21:43
 */
public class WeatherDataSynJob extends QuartzJobBean {

    private static final Logger logger = LoggerFactory.getLogger(WeatherDataSynJob.class);

    @Autowired
    private WeatherDataCollectionService weatherDataCollectionService;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        logger.info("正在同步天气");
        //遍历所有的城市的地址
        List<City> cityList = null;
        try {
            // TODO 待调用接口
            cityList = new ArrayList<City>();
        } catch (Exception e) {
            logger.error("出现错误：", e);
        }
        for (City city : cityList) {
            logger.debug("同步的城市" + city.getCityName());
            weatherDataCollectionService.syncWeatherData(city.getCityId());
        }
        logger.info("同步天气结束");
    }
}
